package com.mercenary.wein.screenControl.ui;

import com.mercenary.wein.screenControl.bean.GroupMetaBean;
import com.mercenary.wein.screenControl.service.GroupService;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;

public class InputDialog extends JDialog {

	static GroupService groupService = new GroupService();

    private GroupComboBox comboBox = new GroupComboBox();

    public void registerGroupComboBox(GroupComboBox comboBox){
        this.comboBox = comboBox;
    }

    public void notifyGroupComboBox(GroupMetaBean gmb){
        comboBox.addItem(gmb);
    }

	public InputDialog(JFrame jf) {
		super(jf, "对话框");
		this.setVisible(true);
		JButton jb1 = new JButton("确定");
		JButton jb2 = new JButton("取消");
		JLabel jl = new JLabel("请输入分组名称：");
		final JTextField groupname =new JTextField();
		JPanel jp = new JPanel();
		jp.setPreferredSize(new  Dimension(300,100));
        this.setLayout(new BorderLayout());
        this.add(jl,BorderLayout.NORTH);
        this.add(groupname,BorderLayout.CENTER);
		groupname.setPreferredSize(new  Dimension(80,20));

        this.setSize(300, 200);
        this.setLocationRelativeTo(jf);
		//jl.setHorizontalAlignment(JLabel.CENTER);
        this.add(jp, BorderLayout.SOUTH);
		jp.setLayout(new FlowLayout());
		jp.add(jb1);
		jp.add(jb2);
		jb1.addActionListener(new ActionListener() {

			public void actionPerformed(ActionEvent arg0) {
				String gname = groupname.getText();
                notifyGroupComboBox(groupService.addGroup(gname));
                dispose();
			}

			
		});
		jb2.addActionListener(new ActionListener() {

			public void actionPerformed(ActionEvent arg0) {
				dispose();

			}

		});
	}}
